import QtQuick 2.6
import QtQuick.Window 2.2
import QtQuick.Layouts 1.3
import QtQuick.Controls 2.2
Window {
    visible: true
    width: 640
    height: 480
    title: qsTr("Hello World")
    Component
    {
        id: msnDelegate
        Item
        {
            id: wrapper
            width: parent.width
            height: 40
            RowLayout
            {
                spacing: 20
                Text { text: PatientID;color: wrapper.ListView.isCurrentItem ? "red" :"blue" ;Layout.preferredWidth: 100}
                Text { text: PatientName;color: wrapper.ListView.isCurrentItem ? "red" :"blue"; Layout.preferredWidth: 50}
                Text { text: model.PatientGender;color: wrapper.ListView.isCurrentItem ? "red" :"blue";Layout.preferredWidth: 50}
                Text { text: PatientBirthday;color: wrapper.ListView.isCurrentItem ? "red" :"blue";Layout.fillWidth: true}
            }

            MouseArea
            {
                anchors.fill: parent
                onClicked: {
                    wrapper.ListView.view.currentIndex = index
                    var data=listview.model.getData(listview.currentIndex)
                    console.log("xxxxx",String(data))
                }

            }
        }
    }

    ListView {
        id:listview
        width: parent.width
        height: parent.height-40*2
        ScrollBar.vertical: ScrollBar {
            id: vBar
            policy: ScrollBar.AsNeeded
            active: vBar.active
        }
        snapMode: ListView.SnapOneItem
        model: myModel
        delegate: msnDelegate
        highlight: Rectangle { color: "lightsteelblue"; radius: 5 }
        currentIndex: 0
    }

    RowLayout{
        id:m_rl
        width: parent.width
        height: 40
        anchors{
            bottom:parent.bottom
            topMargin: 0
        }
        Button{
            id:m_btn
            text:"添加"
            onClicked: myModel.insertData(Qt.formatDateTime(new Date(),"yyyyMMddhhmmss-E"))

        }
        Button{
            text:"删除"
            onClicked: {
                myModel.delCurIndexData(listview.currentIndex)
            }
        }
        Button{
            text:"清理"
            onClicked:myModel.delAllData()
        }
        Button{
            text:"查询"
            onClicked: {
                var data=myModel.getData(listview.currentIndex)
                console.log("xxxxx",String(data))
            }
        }
    }

}

